package TestMethod;

//可变参数列表
public class MethodDemo7 {
    public void sum(int...n){
        int sum=0;
        //遍历可变参数
        for(int i:n){
            sum+=i;
        }
        System.out.println("sum="+sum);
    }
    public static void main(String[] args) {
        MethodDemo7 methodDemo7=new MethodDemo7();
        methodDemo7.sum(1,2,3);
        methodDemo7.sum(1,2,3,4);
        methodDemo7.sum(1,2,3,4,5);
    }
}
